package com.ly.heart.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ly.common.utils.DateUtils;
import com.ly.common.utils.SecurityUtils;
import com.ly.heart.domain.FileEntity;
import com.ly.heart.domain.SurveyRefereeAgreementEntity;
import com.ly.heart.mapper.SurveyRefereeAgreementMapper;
import com.ly.heart.service.IFileInfoService;
import com.ly.heart.service.ISurveyRefereeAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 路条人/合作方居间协议Service业务层处理
 * @author wutao
 * @date 2024-05-24
 */
@Service
public class SurveyRefereeAgreementServiceImpl extends ServiceImpl<SurveyRefereeAgreementMapper, SurveyRefereeAgreementEntity> implements ISurveyRefereeAgreementService {

    @Resource
    private SurveyRefereeAgreementMapper erpSurveyRefereeAgreementInfoMapper;
    @Resource
    private IFileInfoService iFileInfoService;

    /**
     * 查询路条人/合作方居间协议
     * @param id 路条人/合作方居间协议ID
     * @return 路条人/合作方居间协议
     */
    @Override
    public SurveyRefereeAgreementEntity selectErpSurveyRefereeAgreementInfoById (String id) {
        return erpSurveyRefereeAgreementInfoMapper.selectErpSurveyRefereeAgreementInfoById ( id );
    }

    /**
     * 查询路条人/合作方居间协议列表
     * @param erpSurveyRefereeAgreementInfo 路条人/合作方居间协议
     * @return 路条人/合作方居间协议
     */
    @Override
    public List<SurveyRefereeAgreementEntity> selectErpSurveyRefereeAgreementInfoList (SurveyRefereeAgreementEntity erpSurveyRefereeAgreementInfo) {
        List<SurveyRefereeAgreementEntity> surveyRefereeAgreementEntities = erpSurveyRefereeAgreementInfoMapper.selectErpSurveyRefereeAgreementInfoList ( erpSurveyRefereeAgreementInfo );
        //处理附件
        for ( SurveyRefereeAgreementEntity surveyRefereeAgreementEntity : surveyRefereeAgreementEntities ) {
            List<FileEntity> fileEntities = iFileInfoService.list ( new QueryWrapper<FileEntity> ().eq ( "relationId", surveyRefereeAgreementEntity.getId () ) );
            surveyRefereeAgreementEntity.setFileEntities ( fileEntities );
        }
        return surveyRefereeAgreementEntities;
    }

    /**
     * 新增路条人/合作方居间协议
     * @param erpSurveyRefereeAgreementInfo 路条人/合作方居间协议
     * @return 结果
     */
    @Override
    public int insertErpSurveyRefereeAgreementInfo (SurveyRefereeAgreementEntity erpSurveyRefereeAgreementInfo) {
        erpSurveyRefereeAgreementInfo.setCreateTime ( DateUtils.getNowDate () );
        return erpSurveyRefereeAgreementInfoMapper.insertErpSurveyRefereeAgreementInfo ( erpSurveyRefereeAgreementInfo );
    }

    /**
     * 修改路条人/合作方居间协议
     * @param erpSurveyRefereeAgreementInfo 路条人/合作方居间协议
     * @return 结果
     */
    @Override
    public int updateErpSurveyRefereeAgreementInfo (SurveyRefereeAgreementEntity erpSurveyRefereeAgreementInfo) {
        erpSurveyRefereeAgreementInfo.setUpdateTime ( DateUtils.getNowDate () );
        return erpSurveyRefereeAgreementInfoMapper.updateErpSurveyRefereeAgreementInfo ( erpSurveyRefereeAgreementInfo );
    }

    /**
     * 通过路条人Id修改路条人居间协议
     * @param surveyRefereeAgreementEntity
     * @return
     */
    @Override
    public int updateRefereeAgreementByRefereeId (SurveyRefereeAgreementEntity surveyRefereeAgreementEntity) {
        surveyRefereeAgreementEntity.setUpdateTime ( DateUtils.getNowDate () );
        //surveyRefereeAgreementEntity.setUpdateBy ( SecurityUtils.getLoginUser ().getUser ().getUserId () );
        return erpSurveyRefereeAgreementInfoMapper.updateRefereeAgreementByRefereeId ( surveyRefereeAgreementEntity );
    }

    /**
     * 批量删除路条人/合作方居间协议
     * @param ids 需要删除的路条人/合作方居间协议ID
     * @return 结果
     */
    @Override
    public int deleteErpSurveyRefereeAgreementInfoByIds (String[] ids) {
        return erpSurveyRefereeAgreementInfoMapper.deleteErpSurveyRefereeAgreementInfoByIds ( ids );
    }

    /**
     * 删除路条人/合作方居间协议信息
     * @param id 路条人/合作方居间协议ID
     * @return 结果
     */
    @Override
    public int deleteErpSurveyRefereeAgreementInfoById (String id) {
        return erpSurveyRefereeAgreementInfoMapper.deleteErpSurveyRefereeAgreementInfoById ( id );
    }
}
